﻿using System.Windows.Forms;

namespace DotNet.Common
{
    class MenuChanSelect
    {
        public event StringArrayInvoker OnUpdateShowChanList;

        private ContextMenuStrip m_ChanSelectContextMenuStrip;
        private ToolStripMenuItem m_formConfigMenu;
        private string[] m_allChanList, m_showChanList;

        public MenuChanSelect()
        {
            m_ChanSelectContextMenuStrip = new ContextMenuStrip();
            m_formConfigMenu = new ToolStripMenuItem();

            // 
            // m_ChanSelectContextMenuStrip
            // 
            m_ChanSelectContextMenuStrip.Items.AddRange(new ToolStripItem[] {
				m_formConfigMenu});
            m_ChanSelectContextMenuStrip.Name = "ChanSelectContextMenuStrip";
            m_ChanSelectContextMenuStrip.Size = new System.Drawing.Size(113, 142);
            // 
            // m_formConfigMenu
            // 
            m_formConfigMenu.Name = "formConfigMenu";
            m_formConfigMenu.Size = new System.Drawing.Size(112, 22);
            m_formConfigMenu.Text = "显示通道选择(&S)...";

            m_formConfigMenu.Click += new System.EventHandler(m_formConfigMenu_Click);
        }

        public void Load(string[] allChanList, string[] showChanList)
        {
            m_allChanList = allChanList;
            m_showChanList = showChanList;
        }

        public void Show(Control control,int x,int y)
        {
            m_ChanSelectContextMenuStrip.Show(control,x,y);
        }

        void m_formConfigMenu_Click(object sender, System.EventArgs e)
        {
            using (FormChanViewConfig oFormChanViewConfig = new FormChanViewConfig())
            {
                oFormChanViewConfig.Channels.AllChannelList = m_allChanList;
                oFormChanViewConfig.Channels.ShowList = m_showChanList;
                if (oFormChanViewConfig.ShowDialog() == DialogResult.OK)
                {
                    if (OnUpdateShowChanList != null)
                        OnUpdateShowChanList(oFormChanViewConfig.Channels.ShowList);
                }
            }
        }
    }
}
